<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #box {
      width: 500px;
      height: 400px;
      margin: 100px auto;
      border: 1px solid #000;
      font-size: 30px;
      font-weight: 700;
      text-align: center;
      line-height: 400px;
    }
  </style>
  <script>
    // 写一个定时器，每隔一秒修改一次div内文本颜色和文字大小
    // 最开始这个文字是默认大小，大小开始增大，当增大了6次以后
    // 文字大小开始缩小，缩小6次，文字再开始增大，依次循环
    function randomColor() {
      // 借鉴一
      var colorStr = `rgba(${parseInt(Math.random() * 256)}, ${parseInt(Math.random() * 256)}, ${parseInt(Math.random() * 256)}, 1)`
      return colorStr
    }
    // console.log(randomColor());
    window.onload = function() {
      var oDiv = document.getElementById("box")
      var fontSizeSpeed = 10
      var count = 0

      setInterval(() => {
        oDiv.style.color = randomColor()
        // 借鉴二
        var divFontSize = parseInt(getComputedStyle(oDiv)["font-size"])
        oDiv.style.fontSize = divFontSize + fontSizeSpeed + "px"
        count++
        // 借鉴三
        if (count % 6 === 0) {
          fontSizeSpeed *= -1
        }
      }, 300);
    }
  </script>
</head>

<body>
  <div id="box">厚德载物</div>
</body>

</html>